package toy.keli.picmap.util;

import android.util.Log;

import toy.keli.picmap.model.def;
import toy.keli.picmap.model.system;

public class utilStore {
    public static String fileRoot="/data/data/picmap/files/";
    private  String name="";
    private  def data=new def();
    public utilStore(String name){
        this.name=name;
        Log.d("kdebug",getItem(name));
        this.data=new def.json(getItem(name));
    }

    public static def name(String key){
        utilStore obj = new utilStore(key);
        return obj.data;
    }

    @Override
    protected void finalize(){
           setItem(name,data.toJsonString());
    }
    public static int[]  getItemsForInt(String name){
        def d=name(name);
        int rt[]=new int[d.size()];
        for(int i=0;i<d.size();i++)
            rt[i]=d.get(i).toInt();
        return rt;
    }
    private static String getFile(String name){
        return fileRoot+name+".json";
    }
    public static String getItem(String name){
        Log.d("kdebug","read file:"+getFile(name));
        return system.file.get(getFile(name));
    }

    public static boolean setItem(String name,String data){

        Log.d("kdebug","put file: "+getFile(name)+","+data);
         return system.file.put(getFile(name),data);
    }
}
